#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int n;
int by(int x, int y)
{
    int left = 0;
    int right = n - 1;
    int mid = 0;
    int tmp = 0;
    while (left < right)
    {
        mid = (left + right) / 2;
        if (a[mid] < x)
            left = mid + 1;
        else {
            right = mid;
        }
    }
    if (a[left] < x)
    {
        return 0;
    }
    tmp = left;
    left = 0;
    right = n - 1;
    while (left < right)
    {

        mid = (right + left + 1) / 2;
        if (a[mid] <= y)
            left = mid;
        else {
            right = mid - 1;
        }
    }
    if (a[left] > y)
    {
        return 0;
    }
    return left - tmp + 1;

}
int main()
{
    int q, x, y;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    cin >> q;
    while (q--)
    {
        cin >> x >> y;
        cout << by(x, y) << endl;
    }
    return 0;
}